<?php
// $Id: comment.php,v 1.7 2003/11/25 08:51:39 Yoshi.Sakai Exp $
require('header.php');
	if(!xoops_refcheck()){
		redirect_header(XOOPS_URL.'/modules/popnupblog/',2,'Referer Check Failed');
		exit();
	}
	$params = PopnupBlogUtils::getDateFromHttpParams();
//print_r($params);	
	$comment = isset($HTTP_POST_VARS['comment']) ? $HTTP_POST_VARS['comment'] : '';
	$vote = isset($HTTP_POST_VARS['vote']) ? $HTTP_POST_VARS['vote'] : '';
	$name = isset($HTTP_POST_VARS['name']) ? $HTTP_POST_VARS['name'] : "";
	if($params['blogid'] <= 0){
		redirect_header(XOOPS_URL.'/',3,_MD_POPNUPBLOG_NORIGHTTOACCESS.'(0)');
		exit();
	}elseif($comment == '' && $vote == '' ){
		redirect_header(PopnupBlogUtils::createUrl($params['blogid']),3,_MD_POPNUPBLOG_COMMENT_NO_COMMENT);
		exit();
	}
	if(!$xoopsUser){
		if($name == ''){
			$name = _MD_POPNUPBLOG_FORM_ANONYMOUS_NAME;
		}elseif(strlen($name) > 200){
			redirect_header(PopnupBlogUtils::createUrl($params['blogid']), 3, _MD_POPNUPBLOG_COMMENT_NAME_TOO_LONG);
			exit();
		}
	}
	$blog = new PopnupBlog($params['blogid']);
	$dates = $params;
	if(!$dates || !PopnupBlogUtils::isCompleteDate($dates)){
		redirect_header(XOOPS_URL.'/',3,_MD_POPNUPBLOG_INVALID_DATE.'(1.0)');
		exit();
	}
	
	if($comment && !$blog->canComment($params['blogid'])){
		redirect_header(XOOPS_URL.'/',3,_MD_POPNUPBLOG_NORIGHTTOACCESS.'(1)');
		exit();
	}
	if($vote && !$blog->canVote($params['blogid'])){
		redirect_header(XOOPS_URL.'/',3,_MD_POPNUPBLOG_NORIGHTTOACCESS.'(1)');
		exit();
	}
	
	if($blog->insertComment($dates, $name,$comment,$vote)){
		redirect_header(PopnupBlogUtils::createUrl($params['blogid']) ,2,_MD_POPNUPBLOG_THANKS_COMMENT);
		exit();
	}else{
		redirect_header(PopnupBlogUtils::createUrl($params['blogid']) ,2,_MD_POPNUPBLOG_NODUPLICATIONVOTE);
		exit();
	}
require('footer.php');
?>